#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

// ./cp2 a.txt b.txt
// ./cp2 -r a  b
int main(int argc, const char *argv[]){
    if(argc < 3) return -1;

    char **args = (char **)malloc(sizeof(char *) * (argc+1));
    args[0] = "cp";
    for(int i=1; i<argc; i++){
        args[i] = (char *)argv[i];
    }
    args[argc] = NULL;

    if(fork() == 0)    
       execvp("cp", args);
    
    wait(NULL); // 等待子进程（被execvp替换的子进程）
    free(args);
    printf("----over---\n");
    return 0;  
}